﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using DrugStorehouseMIS.Comm;
using DrugStorehouseMIS.DAL.Interface;

namespace DrugStorehouseMIS.DAL
{
    public class ProducterDAL:IProducterDAL
    {
        #region IProducterDAL 成员

        public IDataReader Select(int ProducterNum)
        {
            try
            {
                return SqlDbHelper.RunProcedure_Reader(ConnectionString.ConnString, "Proc_Producter_Select", new SqlParameter[] { new SqlParameter("@ProducterNum", ProducterNum) });
            }
            catch (Exception ex)
            {
                EventLog.WriteErrorLog(ex.Message);
                throw;
            }
        }
        public IDataReader Select(string ProducterName)
        {
            try
            {
                return SqlDbHelper.RunProcedure_Reader(ConnectionString.ConnString, "Proc_Producter_Select_All", new SqlParameter[] { new SqlParameter("@ProducterName", ProducterName) });
            }
            catch (Exception ex)
            {
                EventLog.WriteErrorLog(ex.Message);
                throw;
            }
        }

        public DataTable Select()
        {
            try
            {
                return SqlDbHelper.RunProcedure_DataTable(ConnectionString.ConnString, "Proc_Producter_Select_All");
            }
            catch (Exception ex)
            {
                EventLog.WriteErrorLog(ex.Message);
                throw;
            }
        }

        public int Insert(string ProducterName, string ProducterCode, string Address, string ContactPerson, string Telephone, string Email, string CreditLevel, int FlagDisable)
        {
            try
            {
                SqlParameter[] all = new SqlParameter[]
                {
                    new SqlParameter("@ProducterName",ProducterName),
                    new SqlParameter("@ProducterCode",ProducterCode),
                    new SqlParameter("@Address",Address),
                    new SqlParameter("@ContactPerson",ContactPerson),
                    new SqlParameter("@Telephone",Telephone),
                    new SqlParameter("@Email",Email),
                    new SqlParameter("@CreditLevel",CreditLevel),
                    new SqlParameter("@FlagDisable",FlagDisable)
                };

                return SqlDbHelper.RunProcedure_Query(ConnectionString.ConnString, "Proc_Producter_Insert", all);
            }
            catch (Exception ex)
            {
                EventLog.WriteErrorLog(ex.Message);
                throw;
            }
        }

        public int Update(int ProducterNum, string ProducterName, string ProducterCode, string Address, string ContactPerson, string Telephone, string Email, string CreditLevel, int FlagDisable)
        {
            try
            {
                SqlParameter[] all = new SqlParameter[]
                {
                    new SqlParameter("ProducterNum",ProducterNum),
                    new SqlParameter("@ProducterName",ProducterName),
                    new SqlParameter("@ProducterCode",ProducterCode),
                    new SqlParameter("@Address",Address),
                    new SqlParameter("@ContactPerson",ContactPerson),
                    new SqlParameter("@Telephone",Telephone),
                    new SqlParameter("@Email",Email),
                    new SqlParameter("@CreditLevel",CreditLevel),
                    new SqlParameter("@FlagDisable",FlagDisable)
                };

                return SqlDbHelper.RunProcedure_Query(ConnectionString.ConnString, "Proc_Producter_Update", all);
            }
            catch (Exception ex)
            {           
                EventLog.WriteErrorLog(ex.Message);
                throw;
            }
        }

        public int Delete(int ProducterNum)
        {
            try
            {
                return SqlDbHelper.RunProcedure_Query(ConnectionString.ConnString, "Proc_Supplier_Delete", new SqlParameter[] { new SqlParameter("@ProducterNum", ProducterNum) });
            }
            catch (Exception ex)
            {
                EventLog.WriteErrorLog(ex.Message);
                throw;
            }
        }

        #endregion
    }
}
